<script>
import request from '@/libs/request';

export default {
  name: 'admin-edit',
  data() {
    return {
      modal: false,
      data: {
        id: '',
        para_name: '',
        type: '',
      }
    };
  },
  mounted() {},
  methods: {
    showModal(id = '') {
      this.data.id = id
      this.modal = true;
      this.getInfo()
    },
    getInfo() {
      if (this.data.id) {
        request({
          url: '/admin/info',
          data: {id: this.data.id},
          method: 'post'
        }).then(res => {
          this.data = res.data.data
        })
      }
    },
    back() {
      this.modal = false;
      this.reset()
    },
    reset() {
      this.data = {
        id: '',
        para_name: '',
        type: '',
      }
    },
    submitForm() {
      let loading = this.$loading()
      request({
        url: '/admin/save',
        method: 'post',
        data: this.data,
      }).then(res => {
        loading.close()
        this.reset()
        this.$parent.getList()
        this.modal = false
      }).catch(err => {
        loading.close()
        this.$message.error(err.msg)
      })
    }
  },
};
</script>

<template>
  <el-dialog
    :visible.sync="modal" :title="data.id ? '修改子管理员' : '添加子管理员'" width="600px"
    custom-class="system-type-custom-dialog-style"
  >
    <el-form
      :model="data" label-width="100px"
    >
      <el-form-item label="姓名">
        <el-input v-model="data.real_name" label="姓名"></el-input>
      </el-form-item>

      <el-form-item label="账号">
        <el-input v-model="data.account" label="账号"></el-input>
      </el-form-item>

      <el-form-item label="密码">
        <el-input v-model="data.pwd" label="密码" type="password"></el-input>
      </el-form-item>

      <div class="footer">
        <el-button @click="back">关闭</el-button>
        <el-button type="primary" size="medium" @click="submitForm()">保存</el-button>
      </div>

    </el-form>
  </el-dialog>
</template>

<style scoped>
.footer {
  width: 100%;
  height: 60px;
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 9;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid #e6e6e6;
}
</style>
<style>
.system-type-custom-dialog-style .el-dialog__body {
  height: 300px;
}
</style>